package com.qkl.user.service;

import com.qkl.user.entity.User;
import com.qkl.user.mapper.UserMapper;
import com.qkl.user.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        // 查询用户
        User user = userMapper.getUserByUsername(username);
        if (user == null) {
            throw new UsernameNotFoundException(username);
        }
        // 简化：不设置具体权限（空列表）
        return new LoginUser(
                user.getId(),
                user.getUsername(),
                user.getPassword(),
                Collections.emptyList()  // 无角色权限
        );
    }
}
